#include <cstdio>
#include <unistd.h>
#include<memory>
#include"InetAddress.h"
#include"ChatClient.h"
#include"ChatServer.h"
#include"HttpServer.h"
#include"DBConnPool.h"
#include"Config.h"
#include"Logger.h"
using namespace wjc;
using namespace Http;
#define HTTPSERVER
#ifdef HTTPSERVER

int main(int argc, char* argv[]) {
    uint16_t port = 8080;
    int opt;
    const char* str = "p:a:";
    while ((opt = getopt(argc, argv, str)) != -1)
    {
        switch (opt) {
        case 'p':
            port= atoi(optarg);
            break;
        case 'a':
            Config::isAuth= atoi(optarg);
            break;
        default:
            break;
        }
    }
    net::InetAddress serverAddr(port);
    std::string name = "HttpServer";
    HttpServerPtr serverPtr=std::make_shared<HttpServer>(serverAddr, name);
    auto instance=DBConnPool::getInstance();
    instance->init(Config::db_url, Config::db_User, Config::db_PassWord, Config::db_DatabaseName, Config::db_Port, Config::MaxConn);
    serverPtr->start();
    instance->uninit();
    printf("hello from corenet!\n");
    return 0;

}

#else
#define SERVER
#ifdef SERVER
int main()
{
    uint16_t port = 2070;
    net::InetAddress serverAddr(port);
    std::string name = "ChatServer";
    ChatServer server(serverAddr, name);
    server.start();


    printf("hello from corenet!\n");
    return 0;
}
#else
int main()
{
    uint16_t port = 2070;
    net::InetAddress serverAddr(port);
    std::string name = "ChatClient";
    ChatClient client(serverAddr, name);
    client.start();


    printf("hello from corenet!\n");
    return 0;
}
#endif
#endif